﻿using HB.MsgBus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BaseUsing
{
    internal class Program
    {
        //声明一个消息类型
        delegate void log(string msg);
        static void Main(string[] args)
        {
            MsgBus.OnPublishDoing += (b) =>
            {
                Console.WriteLine($"topic：{b.DelegateName}  call by:{b.PublishFilePath}=>{b.PublishLineNumber}");
                Console.WriteLine($"topic：{b.DelegateName}  call by:{b.SubscribeFilePath}=>{b.SubscribeLineNumber}");
            };
            MsgBus.OnPublishOver += p =>
            {
                Console.WriteLine($"{p.SubscribeFilePath },{p.SubscribeLineNumber}");
            };
            //订阅/注入处理逻辑
            //MsgBus.SubscribeOnce<log>(str =>
            //{
            //    Console.WriteLine(str);
            //});
            ////发布一个调用
            //MsgBus.Publish<log>(t => t("123"));
            //MsgBus.Publish<log>(t => t("123"));
            MsgBus.SubscribeById<Student>("rr", str =>
            {
                Console.WriteLine(str.age);
            });
            //发布一个调用
            Student st1 = new Student() { age = 11, name = "5555" };
            Student st2 = new Student() { age = 18, name = "5555" };
            MsgBus.Publish(st1);
            MsgBus.ClearSubscriptionC<Student>("rr");

            MsgBus.Publish(st2);
            //   MsgBus.Publish<log>(t => t("123"));
            Console.ReadLine();
        }
    }
    public class Student
    {
        public string name { get; set; }
        public int age { get; set; }
    }
}
